<template>
  <div class="app-container msg">
    <el-form :model="queryParam" ref="queryForm" :inline="true"  style="text-align: center;">
      <el-row style="margin: auto; width: 100%; text-align: center; height: 37px;">
        <h1 style="display: inline-block; margin-top: -4px; text-align: center; color: #8b836c; font-size: 1.5rem; letter-spacing: 1px; font-family: serif;">企业微信消息列表</h1>
      </el-row>
      <el-row>
        <el-form-item label="接收人：">
          <el-select v-model="queryParam.receiveUserId" filterable placeholder="请选择（或输入）接收员工" clearable>
            <el-option
              v-for="item in partEmpList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              :title="item.name">
              <span>{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button class="detailBtn" size="small" @click="$router.push('/message/send2')">消息发送</el-button>
          <el-button class="qryBtn" size="small" @click="submitForm">查询</el-button>
        </el-form-item>
      </el-row>
    </el-form>

    <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%">
      <el-table-column prop="id" label="Id"  width="100" />
      <el-table-column prop="title" label="消息标题" show-overflow-tooltip/>
      <el-table-column prop="content" label="消息内容" show-overflow-tooltip />
      <el-table-column prop="receiveUserName" label="接收人"  width="90" />
      <el-table-column prop="createTime" label="创建时间" width="170px"/>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize"
                @pagination="search"/>
  </div>
</template>

<script>

import Pagination from '@/components/Pagination'
import messageApi from '@/api/message'
import partApi from '@/api/parttime'

export default {
  components: { Pagination },
  data () {
    return {
      partEmpList: [],
      queryParam: {
        receiveUserId: null,
        pageIndex: 1,
        pageSize: 10
      },
      listLoading: true,
      tableData: [],
      total: 0
    }
  },
  created () {
    partApi.getEmployeeFilterList().then(res => {
      this.partEmpList = res.response
    })
    this.search()
  },
  methods: {
    search () {
      this.listLoading = true
      messageApi.pageList2(this.queryParam).then(data => {
        const re = data.response
        this.tableData = re.list
        this.total = re.total
        this.queryParam.pageIndex = re.pageNum
        this.listLoading = false
      })
    },
    submitForm () {
      this.queryParam.pageIndex = 1
      this.search()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang='scss'>
.msg .el-pagination {
  white-space: nowrap;
  padding: 2px 5px;
  color: #303133;
  font-weight: bold;
  text-align: center;
}

.msg .el-select {
  display: inline-block;
  position: relative;
  width: 247px;
}
</style>